Focus detection apparatus and method

ABSTRACT

A focus detection apparatus comprises: a sensor unit, having a plurality of photoelectric conversion elements for receiving light that passed through an imaging optical system and accumulating charge, configured to generate an image signal to be used for correlation calculation for focus detection based on the accumulated charge; a control unit configured to control the photoelectric conversion elements to stop charge accumulation in a case where a first signal that represents contrast of the image signal reaches a predetermined voltage level; and a voltage level setting unit. The voltage level setting unit sets a larger voltage level in a first case, in which luminance change in a direction of the correlation calculation in the plurality of the photoelectric conversion elements is gentler than a second case, than in the second case.

BACKGROUND OF THE INVENTION

1. Field of the Invention

The present invention relates to a focus detection apparatus and methodused for automatic focus detection.

2. Description of the Related Art

Conventionally, a variety of cameras or the like having a so-calledautomatic focusing (AF) function have been suggested. The AF function isto automatically focus on a subject by detecting a focus state of thesubject and then changing a position of an imaging lens in response tothe detected focus state. In a method of detecting a focus state, acamera or the like having the AF function makes a subject image beformed on an image sensor comprising a plurality of pixels which includephotoelectric converters. Then, a plurality of pixel signals output fromthe image sensor are subjected to a predetermined calculation, therebythe focus state is detected (See Japanese Patent Laid-Open No.11-150686).

In this method, in order to detect focus states of subjects havingdifferent luminance levels, from a subject with high luminance to asubject with low luminance, at high precision, it is necessary toproperly control a gain used for reading out a signal and a chargeaccumulation period in an image sensor. This is because, if the level ofan image signal of the subject formed from a plurality of pixel signalsis too large, the levels of some pixel signals that can be processed inthe apparatus may exceed a saturation level, the resultant image signalmay be apart from an image signal that properly represents the subject,which results in deterioration of precision. On the contrary, if thelevel of the image signal is too small, a noise in the image signalrelatively increases, which may cause deterioration of precision.

On the other hand, a phase difference detection method is well-known ingeneral as an automatic focus detection method for cameras. With thephase difference detection method, a light flux that comes from asubject and has passed through different exit pupil areas of an imaginglens are caused to form an image on a pair of line sensors ofphotoelectric conversion devices (AF sensors) for focus detection. Thefocus state of the imaging lens is detected by calculating relativepositions of a pair of subject images obtained by performingphotoelectric conversion with the pair of line sensors (hereinafterreferred to as “phase difference calculation”). Recently, various kindsof AF sensors have been proposed in which a plurality of line sensorpairs are arranged such that focus states of a plurality of areas in ascreen can be detected.

For example, Japanese Patent No. 3854704 discloses the followingcontrol. That is to say, photoelectric conversion elements are arrangedat positions corresponding to a plurality of focus detection areas,accumulation time is controlled for respective areas 1 to n bysequentially circulating through and monitoring the area 1 to the arean, and the gain at the time of reading out a pixel signal isappropriately controlled for each area. The pixel signal can be read outwith an appropriate gain even when the subject has different luminancelevels, by appropriately controlling charge accumulation for each area.

In the conventional technique as disclosed in Japanese Patent Laid-OpenNo. 11-150686, accumulation is controlled so that responsiveness andfocus detection precision are both satisfied using a PB signal whichindicates a difference between the maximum value and minimum value of animage signal of the subject. However, if the PB signal of the subject issufficient but the sharpness of the subject is small, focus detectionprecision deteriorates.

Further, with the focus detection apparatus using the photoelectricconversion device disclosed in Japanese Patent No. 3854704, thecirculation cycle is lengthened, possibly resulting in a delay ofaccumulation end timing. For example, in the case where the luminance ofa subject has changed and become brighter while signals of other areasare monitored, in some cases accumulation is not stopped properly, andcharge may be accumulated to a level that exceeds a dynamic range of anoutput circuit of an AF sensor and a dynamic range of an AD converter(saturation). Further, in the case where a subject has a super-highluminance, accumulation end control is not made in time, and in somecases a pixel signal of the super-high luminance area may saturate. Ifthe focus detection calculation is performed using the saturatedsignals, focus detection precision may deteriorate.

SUMMARY OF THE INVENTION

The present invention has been made in consideration of the abovesituation, and is to improve precision of focus detection when sharpnessof a subject is small. Further, the present invention is to performfocus detection with high precision for high luminance subject.

According to the present invention, provided is a focus detectionapparatus comprising: a sensor unit, having a plurality of photoelectricconversion elements for receiving light that passed through an imagingoptical system and accumulating charge, configured to generate an imagesignal to be used for correlation calculation for focus detection basedon the accumulated charge; a control unit configured to control thephotoelectric conversion elements to stop charge accumulation in a casewhere a first signal that represents contrast of the image signalreaches a predetermined voltage level; and a voltage level setting unitconfigured to set the predetermined voltage level, wherein the voltagelevel setting unit sets a larger voltage level as the predeterminedvoltage level in a first case, in which luminance change in a directionof the correlation calculation in the plurality of the photoelectricconversion elements is gentler than a second case, than in the secondcase.

Further, according to the present invention, provided is a focusdetection apparatus comprising: a sensor unit, having a plurality ofphotoelectric conversion elements for receiving light that passedthrough an imaging optical system and accumulating charge, configured togenerate an image signal to be used for correlation calculation forfocus detection based on the accumulated charge; an amplification unitconfigured to amplify the image signal generated by the sensor unit; acontrol unit configured to control the photoelectric conversion elementsto stop charge accumulation in a case where a first signal thatrepresents contrast of the image signal amplified by the amplificationunit reaches a predetermined voltage level; and a gain setting unitconfigured to set a gain for the image signal in the amplification unit,wherein the gain setting unit sets a smaller gain in a first case, inwhich luminance change in a direction of the correlation calculation inthe plurality of photoelectric conversion elements is gentler than asecond case, than in the second case.

Furthermore, according to the present invention, provided is a focusdetection method comprising: a generation step of generating an imagesignal to be used for correlation calculation for focus detection basedon charge accumulated in a plurality of photoelectric conversionelements for receiving light that passed through an imaging opticalsystem and accumulating charge; a control step of controlling thephotoelectric conversion elements to stop the charge accumulation in acase where a first signal that represents contrast of the image signalreaches a predetermined voltage level; and a voltage level setting stepof setting the predetermined voltage level, wherein the voltage levelsetting step sets a larger voltage level as the predetermined voltagelevel in a first case, in which a luminance change in a direction of thecorrelation calculation in the plurality of photoelectric conversionelements is gentler than a second case, than in the second case.

Further, according to the present invention, provided is a focusdetection method comprising: a generation step of generating an imagesignal to be used for correlation calculation for focus detection basedon charge accumulated in a plurality of photoelectric conversionelements for receiving light that passed through an imaging opticalsystem and accumulating charge; an amplification step of amplifying theimage signal generated in the generation step; a control step ofcontrolling the photoelectric conversion elements to stop the chargeaccumulation in a case where a first signal that represents contrast ofthe image signal amplified in the amplification step reaches apredetermined voltage level; and a gain setting step of setting a gainfor the image signal to be used in the amplification step, wherein thegain setting step sets a smaller gain in a first case, in which aluminance change in a direction of the correlation calculation in theplurality of photoelectric conversion elements is gentler than a secondcase, than in the second case.

Further features of the present invention will become apparent from thefollowing description of exemplary embodiments (with reference to theattached drawings).

BRIEF DESCRIPTION OF THE DRAWINGS

The accompanying drawings, which are incorporated in and constitute apart of the specification, illustrate embodiments of the invention, andtogether with the description, serve to explain the principles of theinvention.

FIG. 1 is a block diagram showing a schematic configuration of a camerabody according to an embodiment of the present invention;

FIG. 2 is a diagram showing a configuration of an optical system of thecamera;

FIG. 3 is a diagram showing a detailed configuration of a focusdetection optical system within the optical system shown in FIG. 2;

FIG. 4 is a diagram showing an arrangement of line sensors according toan embodiment;

FIG. 5 is a diagram showing relationship between the line sensors andfocus detection areas according to an embodiment;

FIG. 6 is a block diagram showing a detailed circuit configuration of anAF sensor according to an embodiment;

FIG. 7 is a diagram for explaining a charge accumulation period, asignal level of a PB signal, and timing of accumulation enddetermination;

FIG. 8 is a flowchart of focus detection operation according to anembodiment;

FIG. 9 is a flowchart of AF sensor driving processing according to anembodiment;

FIG. 10 is a flowchart of gain determination processing according to anembodiment;

FIGS. 11A and 11B are diagrams showing examples of relationship betweena gain, accumulation end level, PB signal, gain determination timing,and accumulation end determination timing;

FIG. 12 is a flowchart of pixel signal readout processing according toan embodiment;

FIGS. 13A and 13B are graphs showing examples of pixel signals when again is reset according to the embodiment;

FIG. 14 is a flowchart of determination processing of gain determinationtiming;

FIGS. 15A and 15B are diagrams for explaining difference in sharpness ofa subject; and

FIGS. 16A to 16C are diagrams showing relationship between luminance ofsubject, gain, and focus detection error.

DESCRIPTION OF THE EMBODIMENTS

Exemplary embodiments of the present invention will be described indetail in accordance with the accompanying drawings. The dimensions,shapes and relative positions of the constituent parts shown in theembodiments should be changed as convenient depending on variousconditions and on the structure of the apparatus adapted to theinvention, and the invention is not limited to the embodiments describedherein.

First Embodiment

FIG. 1 is a block diagram showing a schematic configuration of a camerabody equipped with a focus detection sensor according to a firstembodiment of the present invention.

A camera microcomputer (CPU) 100 is connected to a signal input circuit204 for detecting operation on a switch group 214 for various operationsin the camera, an image sensor 206 constituted by a CMOS sensor, a CCD,or the like, an AE sensor 207, a shutter control circuit 208 forcontrolling shutter magnets 218 a and 218 b, and an AF sensor 101. Asignal 215 is transmitted between the CPU 100 and an imaging lens 300,which is shown in FIG. 2 and will be described later, via a lenscommunication circuit 205 in order to control the focus position and adiaphragm. The operation of the camera is determined by a photographeroperating the switch group 214. The switch group 214 includes a releasebutton, a dial for selecting a focus detection area, and the like.

The AF sensor 101 is provided with a plurality of line sensor pairs, andcan obtain a pair of image signals having a parallax with respect toeach other from each line sensor pair, as a result of the CPU 100controlling the AF sensor 101. The AF sensor 101 then detects a focusstate from a phase difference between the obtained pair of imagesignals, and controls the focus position of the imaging lens 300.

The CPU 100 also detects the luminance of a subject by controlling theAE sensor 207, and determines the f-number of the imaging lens 300 andthe shutter speed. The CPU 100 then controls the f-number of the imaginglens 300 via the lens communication circuit 205, controls the shutterspeed by adjusting energizing time of the magnets 218 a and 218 b viathe shutter control circuit 208, and further performs an image sensingoperation by controlling the image sensor 206.

The CPU 100 contains a storage circuit 209 such as a ROM that storesprograms for controlling camera operations, a RAM for storing variables,and an EEPROM (Electronically Erasable Programmable Read Only Memory)for storing various parameters.

Next, a configuration of an optical system of the camera will bedescribed with reference to FIG. 2. Most of incident light beams thatcome from the subject via the imaging lens 300 is reflected upward by aquick return mirror 305 and caused to form a subject image on a finderscreen 303. The photographer can observe this image via a pentaprism 301and an eyepiece 302.

A part of the light beams that have entered the pentaprism 301 is causedto form an image on the AE sensor 207 via an optical filter 312 and animage forming lens 313. The subject luminance can be measured byprocessing an image signal obtained by performing photoelectricconversion on this image.

Another part of the light beams from the subject is transmitted throughthe quick return mirror 305, turned downward by a rear sub-mirror 306,and caused to form an image on the AF sensor 101 after passing through avisual field mask 307, a field lens 311, a diaphragm 308, and asecondary image forming lens 309. A focus state of the imaging lens 300can be detected by processing an image signal obtained by performingphotoelectric conversion on this image. At the time of photographing,the quick return mirror 305 and the sub-mirror 306 jump up and withdrawfrom the optical path, and all incident light beams are thereby causedto form an image on the image sensor 206, and the subject image isexposed.

In FIG. 2, a well-known phase difference detection method is used as thefocus detection method in the focus detection apparatus according to thepresent embodiment, which is constituted by the AF sensor 101 and theoptical system that covers from the visual field mask 307 to thesecondary imaging lens 309. Focus states of a plurality of differentareas within the screen can be detected.

A specific configuration of the optical system related to the focusdetection is shown in FIG. 3. The light beams from the subject that havepassed through the imaging lens 300 are reflected by the sub-mirror 306as described above with reference to FIG. 2, and temporarily caused toform an image in the vicinity of the visual field mask 307 located on asurface conjugate with respect to an imaging surface. Note that theimaging lens 300 is expressed by one lens for the sake of convenience inFIG. 3, however, it is actually comprised of a plurality of lenses. InFIG. 3, the optical paths that are reflected by the sub-mirror 306 andthus turned back are shown in an expanded manner. The visual field mask307 is a member for blocking unnecessary light that enters areas otherthan the focus detection areas in the screen.

The field lens 311 has an effect of projecting an image of each apertureof the diaphragm 308 near the exit pupil of the imaging lens 300. Thesecondary image forming lens 309 is arranged in the rear of thediaphragm 308 and constituted by a pair of lenses, which correspond tothe respective apertures of the diaphragm 308. The light flux that havepassed through the visual field mask 307, the field lens 311, thediaphragm 308, and the secondary image forming lens 309 forms an imageon the line sensors in the AF sensor 101. Although FIG. 3 shows only apair of the line sensors in the AF sensor 101, multiple pairs of theline sensors are arranged, as will be described later.

Next, a relationship between the line sensors in the AF sensor 101 andfocus detection areas within a photographic screen will be describedwith reference to FIGS. 4 and 5.

FIG. 4 is a diagram showing an exemplary arrangement of the line sensorpairs in the AF sensor 101. Each of the line sensor pairs 102-1 to102-11 is constituted by a pair of line sensors, and detects a focusstate based on a phase difference between a pair of signals obtained bythe line sensor pair. For example, the line sensor pair 102-1 isconstituted by a line sensor 102-1A and a line sensor 102-1B. Each linesensor pair detects a phase difference between two images that areoutput from the line sensor pair as a result of substantially the samearea of the subject being projected on the line sensor pair by a focusdetection optical system such as the secondary imaging lens 309, and canthereby detect the focus state.

FIG. 5 is a diagram showing the arrangement of the focus detection areasdisplayed on a finder and AF visual fields obtained by the line sensorpairs in the AF sensor 101. There are a total of 11 focus detectionareas in the first embodiment, and the focus detection areas 1 to 11correspond to the line sensor pairs 102-1 to 102-11, respectively.

Next, a specific circuit configuration of the AF sensor 101 will bedescribed with reference to the block diagram in FIG. 6. A control unit103 is connected to the CPU 100, and controls each block in the AFsensor 101 based on a control command from the CPU 100. The control unit103 has a storage circuit 109 for storing gain information, accumulationperiod information, and so forth, a plurality of registers for flags forvarious control, registers for setting, and timers (not shown).Furthermore, the control unit 103 transmits accumulation endinformation, gain information, accumulation period information, and thelike of the AF sensor 101 to the CPU 100.

The subject image formed by the secondary image forming lens 309 issubjected to photoelectric conversion by the line sensor group 102,which includes the line sensor pairs 102-1 to 102-11, and is accumulatedas charge. The accumulated charge is output as voltage by anamplification circuit. A line sensor selection circuit 104 selects oneof the plurality of line sensor pairs in the line sensor group 102. Theline sensor selection circuit 104 has a function of outputting the pixelsignals of the selected line sensor pair to a PB contrast detectioncircuit 105 that monitors an accumulation state of a feature amount(here, PB contrast) and to an output circuit 108. Further, by driving ashift register 107, the pixel signal is output from the output circuit108 to the CPU 100 pixel by pixel.

The PB contrast detection circuit 105 outputs a PB signal that is adifference between a maximum signal (peak signal) which is the largestof the pixel signals, and a minimum signal (bottom signal) which is thesmallest of the pixel signals of the line sensor pair that was selectedby the line sensor selection circuit 104 and is currently monitored, toan accumulation stop determination circuit 106.

FIG. 7 is a diagram illustrating relationship between a signal level ofthe PB signal which is output from the PB contrast determination circuit105, a charge accumulation period, and timing of accumulation enddetermination. The charge accumulation period 0 indicates a charge starttiming, and the PB signal increases as time elapses. The accumulationstop determination circuit 106 compares the PB signal and anaccumulation end level Vcomp. The level of Vcomp can be changed as willbe described later.

When the PB signal becomes larger than the accumulation end level Vcomp,the accumulation stop determination circuit 106 outputs an accumulationstop determination signal to the control unit 103. In turn, the controlunit 103 outputs an accumulation stop signal to the line sensor group102 to stop charge accumulation in the line sensor pair that wasselected by the line sensor selection circuit 104 and is currentlymonitored. Further, the control unit 103 outputs to the CPU 100 anaccumulation end signal and line information of the line sensor pair inwhich charge accumulation is ended. In a case where the PB signal doesnot reach a target value within a predetermined time period, the CPU 100sends an accumulation stop command to the AF sensor 101 to forcibly stopthe accumulation, and the control unit 103 then outputs an accumulationstop signal to the line sensor group 102.

Here, it is explained that the accumulation stop determination circuit106 performs the accumulation stop determination based on the PB signal.However, the present invention is not limited to this, and theaccumulation stop determination may be performed based on a PD signalwhich is a difference signal between the peak signal and a signal (darksignal) from a pixel shielded from light (not shown).

As described above, the pixel signals accumulated in the line sensorgroup 102 are output to the output circuit 108 via the line sensorselection circuit 104. The CPU 100 sends a control command for readingout pixels and the shift register 107 is driven, thereby pixel signalsare output to an A/D converter (not shown) from the output circuit 108in the CPU pixel by pixel. At this time, the output circuit 108 performsprocesses such as of generation of difference signals between the pixelsignals and the bottom signal (i.e., extract a contrast component), andamplification of the difference signals, and so forth.

Further, the output circuit 108 can output the peak signal, the bottomsignal and the PB signal obtained from the PB contrast detection circuit105 in response to the control command from the CPU 100. Furthermore,the output circuit 108 can output the dark signal, and differencesignals between the dark signal and pixel signals, the peak signal, orthe bottom signal.

Next, the focus detection operation according to the embodiment will beexplained with reference to a flowchart shown in FIG. 8. In step S800,the CPU 100 performs various settings relating to the focus detectionoperation. For example, the CPU 100 communicates with the imaging lens300 via the lens communication circuit 205 to obtain focal lengthinformation, or the like, of the imaging lens 300. Further, the CPU 100sets a maximum charge accumulation period of the AF sensor 101 inaccordance with an operation by a photographer.

In step S801, the CPU 100 controls to drive the AF sensor 101. Thedriving of the AF sensor 101 will be explained later in detail. In stepS802, the CPU 100 reads out pixel signals obtained in response to chargeaccumulated in the AF sensor 101. In step S803, the CPU 100 determineswhether or not the obtained pixel signals are reliable enough to be usedfor focus detection calculation (defocus calculation). Further, the CPU100 also determines which of the signals respectively output from theplurality of the line sensor pairs is to be used for the focus detectioncalculation.

In step S804, the CPU 100 performs the focus detection calculation fordetecting a focus state (a defocus amount) of the imaging lens 300 usingthe obtained pixel signals, and obtains the defocus amount. In stepS805, the CPU 100 determines whether or not the absolute value of thedefocus amount obtained in step S804 is equal to or less than the athreshold defth, and if yes (i.e., if in focus), the focus detectionoperation is ended.

On the contrary, if the absolute value of the defocus amount is greaterthan the threshold defth, the CPU 100 advances the process to step S806,where the CPU 100 drives the imaging lens 300 in accordance with theobtained defocus amount. In step S807, the CPU 100 sets a gaindetermination timing TIME_gd using the obtained pixel signals, gaininformation, and charge accumulation period information. Thedetermination process of the gain determination timing TIME_gd performedin step S807 will be explained later.

After the gain determination timing TIME_gd is set, the CPU 100 advancesthe process to step S801, and the processes of steps S801 to S807 arerepeated until the absolute value of the defocus amount becomes equal toor less than the threshold defth (until the in-focus state is attained).

Next, the AF sensor driving processing performed in step S801 will beexplained in detail. FIG. 9 is a flowchart showing a sub-routine fordriving the AF sensor 101 in step S801. Performed in steps S900 to S903are processes from initial setting operation of the AF sensor 101 andreset operation of circuits to initiation of charge accumulation. Instep S900, the CPU 100 sends a control command to the AF sensor 101, andthe control unit 103 perform settings on each units in accordance withthe sent control command.

In step S901, the control unit 103 resets charge in photoelectricconversion elements of the line sensor pairs 102-1 to 102-11, as well asother circuits, and starts charge accumulation. In step S902, thecontrol unit 103 sets n=1 to set the line sensor pair 102-1 as a linesensor pair to be monitored. In step S903, the control unit 103 resetsand starts to count up a value TIMER of a built-in timer, therebymeasurement of elapsed time since the start of charge accumulationstarts.

In step S904, the control unit 103 controls the line sensor selectioncircuit 104 to select the line sensor pair 102-n (n=1 to 11). At thistime, signals from the line sensor pair 102-n are output to the PBcontrast detection circuit 105. In step S905, the control unit 103compares the value TIMER and the gain determination timing TIME_gd whichis determined as will be described later. Note that the gaindetermination timing TIME_gd is determined in step S807 in FIG. 8.Therefore, in the first routine of the focus detection operation, apredetermined timing TIME_gd1, which will be described later, is set asan initial value of the gain determination timing TIME_gd for theselected line sensor pair 102-n. In a case where TIMER does not reachthe gain determination timing TIME_gd, the control unit 103 advances theprocess to step S906. Contrarily, if TIMER reaches the gaindetermination timing TIME_gd, then the control unit 103 advances theprocess to step S911.

In step S906, the control unit 103 reads out gain information (gain [n])corresponding to the selected line sensor pair 102-n from the storagecircuit 109, and sets the accumulation end level Vcomp of theaccumulation stop determination circuit 106 in accordance with the gaininformation. The gain information is obtained in gain determinationprocess in step S912, which will be explained later, for each linesensor pair in a case where TIMER reaches the gain determination timingTIME_gd. Therefore, until TIMER reaches the gain determination timingtime_gd, the control unit 103 sets a gain GAIN[n] to ×5 (five times) asan initial value for the selected line sensor pair 102-n. Then, a valueVcomp×5 which corresponds the gain of ×5 (five times) is set as theaccumulation end level Vcomp.

In step S907, the control unit 103 resets the built-in timer(TIMER_minitor) and starts counting, thereby measurement of elapsed timeof a monitor period for monitoring an accumulation state of the selectedline sensor pair 102-n is started. In step S908, the accumulation stopdetermination circuit 106 compares the PB signal of the selected linesensor pair 102-n with the accumulation end level Vcomp set in stepS906, and if the PB signal has reached the accumulation end level Vcomp,then the process proceeds to step S913; otherwise the process goes tostep S909.

In steps S909, the control unit 103 compares TIMER_monitor to a monitorperiod PERIOD_monitor for monitoring each line sensor pair. Until theTIMER_monitor reaches the monitor period PERIOD_monitor, theaccumulation stop determination in step S908 is repeated.

If the TIMER_monitor has reached the monitor period PERIOD_monitorwithout stopping of charge accumulation being determined, the controlunit 103 advances the process to step S910, and determines a line sensorpair to be monitored next (next line search). Basically, n is increasedby one to select the line sensor pair to be monitored next; however, ifcharge accumulation of the next line sensor pair has been ended, n isfurther increased by one to determine the next line sensor pair to bemonitored. After n=11, n is set to 1.

Further, if the PB signal reaches the accumulation end level Vcomp whilethe selected line sensor pair 102-n is monitored, the process proceedsto step S913 to perform accumulation end processing. In step S913, thecontrol unit 103 performs accumulation end control and pixel signalstoring control, and the value of the timer TIMER is stored as thecharge accumulation period in the storage circuit 109 inside of thecontrol unit 103.

In step S914, the control unit 103 determines whether or not chargeaccumulation of all the line sensor pairs is finished. If yes, the AFsensor driving processing ends, whereas if not, the control unit 103advances the process to step S910, where the next line search isperformed.

If the timer has reached the gain determination timing TIME_gd in stepS905, the control unit 103 determines whether or not gains for all theline sensor pairs have been determined in step S911. If not, the processproceeds to step S912 where gain determination processing is repeated ina procedure which will be described later until the gains for all theline sensor pairs are determined.

If the gains for all the line sensor pairs have been determined, thecontrol unit 103 advances the process to step S906. At this point, gaininformation (GAIN[n]) for each line sensor pair is stored in the storagecircuit 109. Accordingly, in step S906, the control unit 103 reads outthe gain information (GAIN[n]) corresponding to the selected line sensorpair 102-n from the storage circuit 109, and sets the accumulation endlevel Vcomp for the accumulation stop determination circuit 106 on thebasis of the readout gain information. The processes after step S907 arethe same as those performed when the timer TIMER has not reached thegain determination timing TIME_gd.

Next, the gain determination processing performed in step S912 will beexplained with reference to FIG. 10. In step S1000, the control unit 103sets the accumulation end level Vcomp for the accumulation stopdetermination circuit 106 to a predetermined value Vcomp×10. In stepS1001, if it is determined based on the output from the accumulationstop determination circuit 106 that the PB signal is equal to or greaterthan the accumulation end level Vcomp (here, Vcomp×10), the control unit103 advances the process to step S1009, where the gain GAIN[n] for theline sensor pair 102-n is set to 5 times (×5), and written to thebuilt-in storage circuit 109.

If the PB signal is smaller than the accumulation end level Vcomp (hereVcomp×10), the process proceeds to step S1002, where the control unit103 sets the accumulation end level Vcomp for the accumulation stopdetermination circuit 106 to a predetermined value Vcomp×20 which issmaller than the value Vcomp×10. In step S1003, if it is determinedbased on the output from the accumulation stop determination circuit 106that the PB signal is equal to or greater than the accumulation endlevel Vcomp (here Vcomp×20), the control unit 103 advances the processto step S1008, where the gain GAIN[n] for the line sensor pair 102-n isset to 10 times (×10), and written to the built-in storage circuit 109.

If the PB signal is smaller than the accumulation end level Vcomp (hereVcomp×20), the process proceeds to step S1004, where the control unit103 sets the accumulation end level Vcomp for the accumulation stopdetermination circuit 106 to a predetermined value Vcomp×40 which issmaller than the value Vcomp×20. In step S1005, if it is determinedbased on the output from the accumulation stop determination circuit 106that the PB signal is equal to or greater than the accumulation endlevel Vcomp (here Vcomp×40), the control unit 103 advances the processto step S1007 where the gain GAIN[n] for the line sensor pair 102-n isset to 20 times (×20), and written to the built-in storage circuit 109.On the other hand, if the PB signal is smaller than the accumulation endlevel Vcomp (here Vcomp×40), the process proceeds to step S1006, wherethe gain GAIN[n] for the line sensor pair 102-n is set to 40 times(×40), and written to the built-in storage circuit 109.

As described above, the control unit 103 sets Vcomp to Vcomp×5,Vcomp×10, Vcomp×20, or Vcomp×40 in accordance with the level of the PBsignal. Then, based on the comparison result between the PB signal andthe set Vcomp, the gain GAIN[n] to be set for the line sensor pair 102-nis determined and written to the built-in storage circuit 109.

When the gain GAIN[n] for the selected line sensor pair 102-n isdetermined, the process proceeds to step S910, and the next line sensorpair to be monitored is determined as described above (next linesearch).

As described above, processes from steps S904 to S914 are repeated, andwhen the accumulation end processing for all the line sensor pairs isfinished, the AF sensor driving processing ends. Although it is notshown in the drawings, when a forcible accumulation stop command is sentfrom the CPU 100, the control unit 103 forcibly advances the processfrom step S905 to S906, and from step S908 to S913, and the accumulationend processing is performed.

FIGS. 11A and 11B are diagrams showing examples of relationship betweenthe gain GAIN[n] which is set in the processing shown in FIG. 10, thegain determination timing TIME_gd, and timing of accumulation enddetermination. In the example shown in FIG. 11A, the PB signal is inbetween the accumulation end levels Vcomp×10 and Vcomp×20 at the gaindetermination timing TIME_gd. in this case, according to the flowchartshown in FIG. 10, the control unit 103 determines the gain GAIN[n] as 10times (×10). In step S906 in FIG. 9, the control unit 103 reads out thegain information (GAIN[n]=×10) for the line sensor pair 102-n from thestorage circuit 109, and sets the accumulation end level Vcomp in theaccumulation stop determination circuit 106 to Vcomp×10.

In the example shown in FIG. 11B, the PB signal is smaller than theaccumulation end level Vcomp×40 at the gain determination timingTIME_gd. In this case, according to the flowchart shown in FIG. 10, thecontrol unit 103 determines the gain GAIN[n] as 40 times (×40). In stepS906 in FIG. 9, the control circuit 103 reads out the gain information(GAIN[n]=×40) for the line sensor pair 102-n from the storage circuit109, and sets the accumulation end level Vcomp in the accumulation stopdetermination circuit 106 to Vcomp×40.

Note that Vcomp×5, Vcomp×10, Vcomp20 and Vcomp×40 are set so that chargeaccumulation is stopped at a level such that, when the pixel signals areamplified by the respective gain and output from the output circuit 108,the signals will not exceed (or saturate) the dynamic range of theoutput circuit 108 and an input dynamic range of the A/D converter ofthe CPU 100.

The lower the gain set in the gain determination is and the higher theaccumulation end level is, the larger the accumulated signal amount (S)becomes and the larger the S/N ratios of obtained pixel signals become.As the S/N ratios of the obtained pixel signals increase, focusdetection precision improves.

However, in a case where the luminance or contrast of a subject is low,the maximum charge accumulation period of the AF sensor 101 will elapsebefore the PB signal reaches the accumulation end level, and asufficient signal amount (S) will not be obtained. For the sameaccumulated charge amount, the S/N ratio becomes larger by amplifying apixel signal with a higher gain due to a quantization error by the A/Dconverter of the CPU 100 and an effect of implementation noise of theCPU 100 and the AF sensor.

Accordingly, the gain determination timing TIME_gd is set inconsideration of a balance between the S/N ratio and a chargeaccumulation period (response when driving the AF sensor 101), and soforth.

Further, the gain set in the gain determination processing in step S912is also used at the time of pixel signal readout operation performed instep S802. In a case where a control command for setting the readoutgain is not sent from the CPU 100, the control unit 103 reads out thegain GAIN[n] from the storage circuit 109 at the time of outputting thepixels signals, and sets it as a readout gain in the output circuit 108.

Next, the pixel signal readout processing performed in step S802 will beexplained in detail with reference to a flowchart of FIG. 12. In stepS1200, the CPU 100 selects the line sensor pair 102-n from which pixelsignals are to be read out, and sends a command for selecting a linesensor pair to the AF sensor 101. The control unit 103 of the AF sensor101 controls the line sensor selection circuit 104 to select the linesensor pair 102-n.

In step S1201, the CPU 100 reads out the gain information andaccumulation period information of the selected line sensor pair 102-nfrom the AF sensor 101. The gain information corresponds to the value(GAIN[n]) set for each line sensor pair in the gain determinationprocessing in step S912. The accumulation period information is used inthe determination processing of TIME_gd, which will be explained later,performed in step S807. Then, in step S1202, the CPU 100 sets the gaininformation GAIN[n] read out from the AF sensor 101 as the GAIN_rd to beused at the time of reading out the pixel signals.

In step S1203, the CPU 100 reads out a feature amount of the pixelsignals. Here, the feature amount of the pixel signals is the PB signalof the selected line sensor pair. However, the feature amount is notlimited to the PB signal, and may be a peak signal and bottom signal ofthe selected line sensor pair. Or the feature amount may be differencesignals between the peak signal and a signal (dark signal) output from apixel shielded from light, or between the bottom signal and the darksignal.

The CPU 100 sends the control command for reading out the feature amountto the AF sensor 101. The control unit 103 controls the PB contrastdetection circuit 105 and the output circuit 108 based on the receivedcommand, and the AF sensor 101 sends the PB signal to the CPU 100. Atthis time, a low gain is set to the output circuit 108 so that the PBsignal does not saturate. Here, it is assumed that the gain foroutputting the feature amount is 2.5 times (×2.5).

In step S1204, the CPU determines whether or not any of the pixelsignals may saturate in a case where the pixel signals are read out withthe GAIN_rd set in step S1202 in accordance with the feature amount readout in step S1203. In this step, the PB signal is converted to a valuewhen it is output with GAIN_rd using a ratio between the gain (2.5times) at the time of outputting the feature amount and GAIN_rd to beused at the time of reading the pixel signals. Whether or not the pixelsignals will saturate is determined by determining whether or not theconverted PB signal exceeds the upper limit of input voltage (e.g.,3.2V) of the A/D converter of the CPU 100. Since the peak signal whichis a base signal of the PB signal is the largest of the pixel signalsoutput from the line sensor pair, by performing saturation determinationbased on the PB signal, it is possible to determined whether or not anyof the pixel signals may saturate.

If it is determined that any of the pixel signals may saturate, the CPU100 advances the process to step S1205, whereas if it is determined thatno pixel signal will saturate, the CPU 100 advances the process to stepS1208. In step S1205, the CPU 100 halves the readout gain GAIN_rd.

In step S1206, the CPU 100 determines the readout gain GAIN_rd. If theGAIN_rd is smaller than the minimum gain (here 2.5 times) that can beset in the AF sensor 101, the CPU 100 advances the process to stepS1207. On the contrary, if the GAIN_rd exceeds ×2.5 (2.5 times), the CPU100 advances the process to step S1204, and the saturation determinationis repeated according to the flowchart.

Note that the reason for not setting the gain to 2.5 times in the gaindetermination process in step S912 is to shorten the accumulationperiod. The accumulation end level Vcomp for reading out with the gain×2.5 is twice as large as Vcomp×5. In other words, as shown in FIGS. 11Aand 11B, in order to set a lower gain, it takes a longer chargeaccumulation period until the PB signal reaches the accumulation enddetermination level. Therefore, according to the embodiment, the minimumgain upon resetting the readout gain is made different from a gain setin the gain determination processing, thereby realizing reduction of thecharge accumulation period and precision at the same time.

In step S1207, the CPU 100 sends a command to set the GAIN_rd determinedin steps S1204 to S1206 to the AF sensor 101. However, if saturation hasnot been determined in step S1204 even once, the process in step S1207is not performed. This is because, in a case where a command to set areadout gain is not sent from the CPU 100, the AF sensor 101 amplifiesthe pixel signals with the gain determined in the gain determinationprocess in step S912 and outputs the amplified pixel signals.

In step S1208, the CPU 100 controls the AF sensor 101 to readout thepixel signals from the selected line sensor pair 102-n. In step S1209,the control unit 103 determines whether or not pixel signals are readout from all the line sensor pairs, and if not, the process returns tostep S1200, the next sensor pair is selected, and the above processesare repeated. On the contrary, if pixel signals are read out from allthe line sensor pairs, the image signal readout processing is ended.

FIG. 13A shows an example where some of pixel signals are saturated whenthey are read out with a gain (GAIN[n]) (10 times, for example) set inthe gain determination processing in step S912. The original imagesignal (shown by a broken line) is clipped at the upper limit of theinput voltage range of the CPU 100 or of the output voltage range of theoutput circuit 108.

When the same pixel signals are read out with the GAIN_rd (5 times, forexample) that is reset in steps S1204 to S1206, the resultant imagesignal is as shown in FIG. 13B. Thus, it is possible to read out thepixel signals without any of the pixel signals being saturated. Further,if part of the plurality of pixels in a pixel unit of the AF sensor 101is saturated, saturation due to the input voltage range of the CPU 100and the output voltage range of the output circuit 108 can berestrained, thereby reducing the effect to the focus detectionprecision.

Further, if saturation is determined using pixel signals, it isnecessary to read out all the pixels, which requires a long processingtime. In contrast, according to the present invention, only the featureamount is read out to determine presence of a saturated signal beforereading out pixel signals, it is possible to shorten time taken forreadout.

After reading pixel signals in step S802 as described above, the CPU 100determines reliability of the pixel signals in step S803. Indetermination, a contrast of the subject, for example, is calculatedfrom the pixel signals, and if the contrast is lower than apredetermined value (reliability judgment threshold), then it isdetermined that the pixel signals are not reliable. However, as shown inFIG. 13B, a signal read out after resetting the gain has a smalleramplitude, and it is judged that the contrast is low. Accordingly, thereliability judgment threshold applied to the signal read out after thegain is reset is changed to a value suitable for judging the reliabilityon the basis of the read gain information and charge accumulationperiod.

Next, the determination processing of the gain determination timingTIME_gd performed in step S807 will be explained in detail withreference to FIG. 14. In step S807, the CPU 100 determines whether toset TIME_gd1 or TIME_gd2 as the gain determination timing TIME_gd basedon the pixel signals which are determined to be reliable in step S803and used for calculating the defocus amount from viewpoints of focusdetection precision and responsiveness. Note, TIME_gd1 is smaller thanTIME_gd2.

In step S1400, the CPU 100 calculates sharpness of the subject from theobtained pixel signals. The sharpness will be described in detail withreference to FIGS. 15A and 15B. FIGS. 15A and 15B show examples of pixelsignals that the CPU 100 reads out from the AF sensor 101. Here, imagesobtained from one of the line sensor pair are shown for the sake ofsimplifying the explanation. In FIGS. 15A and 15B, the abscissaindicates a pixel position, and the ordinate indicates the pixel signallevel. FIG. 15A shows an example of pixel signals with high sharpness,and FIG. 15B shows an example of pixel signals with low sharpness.

The amplitudes (contrast) of the pixel signals shown in FIGS. 15A and15B are the same, however, the change in signal level shown in FIG. 15Ais steep, and the change in signal level shown in FIG. 15B is gentle.Therefore, it can be said that the sharpness of the pixel signals shownin FIG. 15A is higher than that shown in FIG. 15B.

In order to quantitatively calculate the sharpness, the followingformulas (1), (2) and (3) are used, for example.

$\begin{matrix}{{1^{st}\mspace{14mu}{Order}\mspace{14mu}{Contrast}} = {\sum\limits_{i = 0}^{m - 1}{{{A(i)} - {A\left( {i + 1} \right)}}}}} & (1) \\{{2^{nd}\mspace{14mu}{Order}\mspace{14mu}{Contrast}} = {\sum\limits_{i = 0}^{m - 1}{{{A(i)} - {A\left( {i + 1} \right)}}}^{2}}} & (2) \\{{Sharpness} = {\left( {2^{nd}\mspace{14mu}{order}\mspace{14mu}{contrast}} \right)/\left( {1^{st}\mspace{14mu}{Order}\mspace{14mu}{Contrast}} \right)}} & (3)\end{matrix}$

Calculated with the formula (1) is the sum of the differences betweenpixel signals from adjoining pixels from the 0-th pixel to the (m−1)-thpixel, and calculated with the formula (2) is the sum of squares of thedifferences between pixel signals from adjoining pixels from the 0-thpixel to the (m−1)-th pixel. Calculated with the formula (3) is a ratioof the 2^(nd) order contrast calculated with the formula (2) to the1^(St) order contrast calculated with the formula (1). The gentler thechange in signal level is, the smaller a value calculated with theformula (3) which shows the sharpness becomes. If the amplitudes(contrast) of pixel signals are same, a lower sharpness causes lowerfocus detection precision and larger focus detection error.

In step S1401, the CPU 100 determines whether the value of the sharpnesscalculated in step S1400 is equal to or less than a predetermined valueSth. If yes, the CPU 100 advances the process to step S1402. Contrarily,if the value of the sharpness is greater than the predetermined valueSth, the CPU 100 advances the process to S1405, and sets the gaindetermination timing TIME_gd to TIME_gd1.

In step S1402, the CPU 100 determines whether or not the chargeaccumulation period is equal to or shorter than a predetermined periodTth. If yes, the CPU 100 advances the process to step S1403. Contrarily,if the accumulation period is longer than the predetermined period Tth,the CPU 100 advances the process to step S1405, and sets the gaindetermination timing TIME_gd to TIME_gd1.

In step S1403, the CPU 100 determines whether or not the gain GAIN[n]set in the gain determination processing is equal to or greater than apredetermined value Gth. This determination is equivalent to thedetermination using the accumulation end level set in the gaindetermination processing. If the gain GAIN[n] is equal to or greaterthan the predetermined value Gth, the CPU 100 advances the process tostep S1404, and sets the gain determination timing TIME_gd to TIME_gd2.Contrarily, if the gain GAIN[n] is smaller than the predetermined valueGth, the CPU 100 advances the process to step S1405, and sets the gaindetermination timing TIME_gd to TIME_gd1.

Next, the difference between the results of gain determinationprocessing due to the difference between the gain determination timingwill be explained in detail with reference to FIGS. 11A and 11B. In theexample shown in FIG. 11B, the PB signal is smaller than Vcomp×40 at thetime TIME_gd1. Therefore, according to the flowchart of FIG. 10 asdescribed above, the control unit 103 determines the gain GAIN[n] as 40times (×40). In step S906 in FIG. 9, the control unit 103 reads out thegain information (GAIN[n]=40 times) from the storage circuit 109, andsets Vcomp×40 to the accumulation end level Vcomp of the accumulationstop determination circuit 106.

In contrast, in FIG. 11A, the PB signals is in between Vcomp×10 andVcomp×20 at the time TIME_gd2. According to the flowchart of FIG. 10 asdescribed above, the control unit 103 determines the gain GAIN[n] as 10times (×10). Namely, as shown in FIGS. 11A and 11B, by elongating thegain determination timing TIME_gd, it is possible to set a low gain. Instep S906 in FIG. 9, the control unit 103 reads out the gain information(GAIN[n]=10 times) from the storage circuit 109, and sets Vcomp×10 tothe accumulation end level Vcomp of the accumulation stop determinationcircuit 106.

According to the processing as described above, the gain determinationtiming TIME_gd is set to TIME_gd2 in a case where sharpness a subject islow even if the subject is bright, thus the accumulation end level Vcompbecomes high, and more charge can be accumulated. Consequently, the S/Nratio of the obtained signal becomes high, which realizes focusdetection with high precision.

Note that, in the processing shown in FIG. 14, the reason for judgingthe charge accumulation period in step S1402 is to distinguish a casewhere calculated sharpness becomes low due to the low luminance or lowcontrast of the subject. Further, by judging the gain in step S1403, itis controlled such that the gain determination timing TIME_gd is keptshort if the gain is set low even if the sharpness is low.

Next, the relationship between the luminance of a subject, a gain set inthe gain determination processing, and a focus detection error isexplained with reference to FIGS. 16A to 16C. For the sake of simplicityof explanation, it is assumed that the pixel signals are not saturated,and a gain is not reset in step S802.

FIG. 16A shows a relationship between the luminance of a subject and afocus detection error, assuming that the subject is the same as thatshown in FIG. 15A, with the gain determination timing TIME_gd being setto TIME_gd1. Note that the unit of the luminance of the subject is shownby a EV value converted with the ISO sensitivity of 100.

As described above, a gain to be used for reading out pixel signals areset based on a gain obtained at the gain determination timing TIME_gd,and the luminance and contrast (PB signal) of a subject. In a luminancerange which is brighter than EV2, the charge accumulation will not beforcibly stopped and the signals reaches the accumulation end levelVcomp, and thus the focus detection error increases as a lower gain isset. Further, in a luminance range which is darker than EV2, theaccumulation end determination is not performed within the maximumaccumulation period and charge accumulation is forcibly stopped.Accordingly, pixel signals decrease as the luminance decreases, and thefocus detection error increases.

FIG. 16B shows a relationship between the luminance of a subject and afocus detection error, assuming that the subject is the same as thatshown in FIG. 15B, with the gain determination timing TIME_gd being setto TIME_gd1. FIG. 15B shows the subject whose sharpness is lower thanthe subject shown in FIG. 15A, the focus detection error is greater inthe case of FIG. 16B than in the case of FIG. 16A.

FIG. 16C shows a relationship between the luminance of a subject and afocus detection error, assuming that the subject is the same as thatshown in FIG. 15B, with the gain determination timing TIME_gd being setto TIME_gd2. Since the gain determination timing TIME_gd comes laterthan the case shown in FIG. 16B, a lower gain is set compared to thecase of FIG. 16B. Accordingly, it is possible to obtain high focusdetection precision in the luminance range from EV4 to EV8. However, asthe charge accumulation period becomes longer in this luminance range,responsiveness when driving the AF sensor 101 decreases.

According to the embodiment of the present invention, in a case where itis determined that a subject is of low sharpness which causes low focusdetection precision, by delaying the gain determination timing, thesignal level which will be obtained is increased. As a result, it ispossible to perform focus detection with high precision.

Further, according to the embodiment of the present invention, a featureamount of pixel signals of accumulated charge is read out, and thedetermination on saturation at the time of reading out pixel signalsusing a gain set by the gain determination processing is performed. Thegain may be reset in accordance with the determination result, therebyan appropriate gain is set and pixel signals are read out. As a result,it is possible to reduce the saturation of pixel signals.

Note that in the embodiment of the present invention, it is explainedthat the control is made on the basis of a difference signal between thepeak signal and the bottom signal, however, the dark signal may be usedinstead of the bottom signal.

Further, the numbers of options which can be set to the gain, theaccumulation end level, and the gain determination timing are notlimited to the above, and can be increased or decreased as appropriate.Furthermore, in the above embodiment, discrete values are used asoptions for the gain, the accumulation end level, and the gaindetermination timing, however, continuous values may be used.

While the present invention has been described with reference toexemplary embodiments, it is to be understood that the invention is notlimited to the disclosed exemplary embodiments. The scope of thefollowing claims is to be accorded the broadest interpretation so as toencompass all such modifications and equivalent structures andfunctions.

This application claims the benefit of Japanese Patent Application No.2014-070085, filed on Mar. 28, 2014 which is hereby incorporated byreference herein in its entirety.

What is claimed is:
 1. A focus detection apparatus comprising: a sensorunit, having a plurality of photoelectric conversion elements forreceiving light that passed through an imaging optical system andaccumulating charge, configured to generate an image signal to be usedfor correlation calculation for focus detection based on the accumulatedcharge; a control unit configured to control the photoelectricconversion elements to stop charge accumulation in a case where a firstsignal that represents contrast of the image signal reaches apredetermined voltage level; and a voltage level setting unit configuredto set the predetermined voltage level, wherein the voltage levelsetting unit sets a larger voltage level as the predetermined voltagelevel in a first case, in which luminance change in a direction of thecorrelation calculation in the plurality of the photoelectric conversionelements is gentler than a second case, than in the second case.
 2. Thefocus detection apparatus according to claim 1, further comprising anamplification unit configured to amplify the image signal generated bythe sensor unit, wherein the first signal represents the contrast of theimage signal amplified by the amplification unit.
 3. The focus detectionapparatus according to claim 2, further comprising a gain setting unitconfigured to set a gain for the image signal in the amplification unit,wherein the gain setting unit sets a smaller gain in the first case thanin the second case.
 4. The focus detection apparatus according to claim3, further comprising a time setting unit configured to set a period oftime since the charge accumulation in the photoelectric conversionelements is started until the gain is set by the gain setting unit,wherein the time setting unit sets a longer period time in the firstcase than in the second case.
 5. The focus detection apparatus accordingto claim 4, wherein the gain setting unit sets the gain in accordancewith a voltage level of the first signal at a time when the period oftime set by the time setting unit has elapsed since the chargeaccumulation in the photoelectric conversion elements is started.
 6. Thefocus detection apparatus according to claim 4, wherein the voltagelevel setting unit sets the predetermined voltage level in accordancewith a voltage level of the first signal at a time when the period oftime set by the time setting unit has elapsed since the chargeaccumulation in the photoelectric conversion elements is started.
 7. Thefocus detection apparatus according to claim 3, further comprising areadout unit configured to read out the image signal amplified by theamplification unit, wherein the control unit controls the chargeaccumulation in the photoelectric conversion elements in accordance withthe first signal that is based on the image signal amplified by a firstgain, and the readout unit reads out the image signal amplified by asecond gain that is smaller than the first gain in a case where avoltage level of the first signal that is based on the image signalamplified by the first gain exceeds a predetermined threshold.
 8. Thefocus detection apparatus according to claim 7, further comprising afocus detection unit configured to perform the correlation calculationusing the image signal read out by the readout unit and detect a defocusamount.
 9. The focus detection apparatus according to claim 8, whereinthe focus detection unit determines reliability of the image signal readout by the readout unit, and a threshold used for the determination ofreliability changes depending on a gain used upon reading out the imagesignal by the readout unit.
 10. The focus detection apparatus accordingto claim 1, further comprising a calculation unit configured tocalculate an evaluation value representing a ratio between a sum totalof squares of luminance differences between adjoining photoelectricconversion elements and a sum total of the luminance differences betweenthe adjoining photoelectric conversion elements, wherein the voltagelevel setting unit changes the predetermined voltage level depending onthe evaluation value calculated by the calculation unit.
 11. A focusdetection apparatus comprising: a sensor unit, having a plurality ofphotoelectric conversion elements for receiving light that passedthrough an imaging optical system and accumulating charge, configured togenerate an image signal to be used for correlation calculation forfocus detection based on the accumulated charge; an amplification unitconfigured to amplify the image signal generated by the sensor unit; acontrol unit configured to control the photoelectric conversion elementsto stop charge accumulation in a case where a first signal thatrepresents contrast of the image signal amplified by the amplificationunit reaches a predetermined voltage level; and a gain setting unitconfigured to set a gain for the image signal in the amplification unit,wherein the gain setting unit sets a smaller gain in a first case, inwhich luminance change in a direction of the correlation calculation inthe plurality of photoelectric conversion elements is gentler than asecond case, than in the second case.
 12. The focus detection apparatusaccording to claim 11, further comprising a voltage level setting unitconfigured to set the predetermined voltage level, wherein the voltagelevel setting unit sets a larger voltage level as the predeterminedvoltage level in the first case than in the second case.
 13. The focusdetection apparatus according to claim 11, further comprising a timesetting unit configured to set a period of time since the chargeaccumulation in the photoelectric conversion elements is started untilthe gain is set by the gain setting unit, wherein the time setting unitsets a longer period time in the first case than in the second case. 14.The focus detection apparatus according to claim 13, wherein the gainsetting unit sets the gain in accordance with a voltage level of thefirst signal at a time when the period of time set by the time settingunit has elapsed since the charge accumulation in the photoelectricconversion elements is started.
 15. The focus detection apparatusaccording to claim 13, wherein the voltage level setting unit sets thepredetermined voltage level in accordance with a voltage level of thefirst signal at a time when the period of time set by the time settingunit has elapsed since the charge accumulation in the photoelectricconversion elements is started.
 16. The focus detection apparatusaccording to claim 11, further comprising a readout unit configured toread out the image signal amplified by the amplification unit, whereinthe control unit controls the charge accumulation in the photoelectricconversion elements in accordance with the first signal that is based onthe image signal amplified by a first gain, and the readout unit readsout the image signal amplified by a second gain that is smaller than thefirst gain in a case where a voltage level of the first signal that isbased on the image signal amplified by the first gain exceeds apredetermined threshold.
 17. The focus detection apparatus according toclaim 16, further comprising a focus detection unit configured toperform the correlation calculation using the image signal read out bythe readout unit and detect a defocus amount.
 18. The focus detectionapparatus according to claim 17, wherein the focus detection unitdetermines reliability of the image signal read out by the readout unit,and a threshold used for the determination of reliability changesdepending on a gain used upon reading out the image signal by thereadout unit.
 19. The focus detection apparatus according to claim 12,further comprising a calculation unit configured to calculate anevaluation value representing a ratio between a sum total of squares ofluminance differences between adjoining photoelectric conversionelements and a sum total of the luminance differences between theadjoining photoelectric conversion elements, wherein the voltage levelsetting unit changes the predetermined voltage level depending on theevaluation value calculated by the calculation unit.
 20. A focusdetection method comprising: a generation step of generating an imagesignal to be used for correlation calculation for focus detection basedon charge accumulated in a plurality of photoelectric conversionelements for receiving light that passed through an imaging opticalsystem and accumulating charge; a control step of controlling thephotoelectric conversion elements to stop the charge accumulation in acase where a first signal that represents contrast of the image signalreaches a predetermined voltage level; and a voltage level setting stepof setting the predetermined voltage level, wherein the voltage levelsetting step sets a larger voltage level as the predetermined voltagelevel in a first case, in which a luminance change in a direction of thecorrelation calculation in the plurality of photoelectric conversionelements is gentler than a second case, than in the second case.
 21. Afocus detection method comprising: a generation step of generating animage signal to be used for correlation calculation for focus detectionbased on charge accumulated in a plurality of photoelectric conversionelements for receiving light that passed through an imaging opticalsystem and accumulating charge; an amplification step of amplifying theimage signal generated in the generation step; a control step ofcontrolling the photoelectric conversion elements to stop the chargeaccumulation in a case where a first signal that represents contrast ofthe image signal amplified in the amplification step reaches apredetermined voltage level; and a gain setting step of setting a gainfor the image signal to be used in the amplification step, wherein thegain setting step sets a smaller gain in a first case, in which aluminance change in a direction of the correlation calculation in theplurality of photoelectric conversion elements is gentler than a secondcase, than in the second case.